-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Faster optimized frozen dictionary creation (6/6) #88093
Conversation
… for creation time for collections with <= 4 items
…n we receive a Dictionary/HashSet where there are key we know that all hash codes are unique and we can avoid some work later 10-15% CPU time gain and 15-20% allocation reduction for FrozenDictionary and FrozenHashSet where TKey is uint, short, ushort, byte, sbyte
…plication and decrease code size
Tagging subscribers to this area: @dotnet/area-system-collections Issue Details
@stephentoub this is my last PR for frozen collections perf for now I apologize if the CI gets red, for some reason I am getting a build error and I temporarily can't run unit tests locally:
|
@adamsitnik what commit on main is your branch based on? I believe I fixed the build break you're seeing, so I want to make sure it didn't break in a different way. |
...ibraries/System.Collections.Immutable/src/System/Collections/Frozen/SmallFrozenDictionary.cs
Show resolved
Hide resolved
src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/Constants.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Collections.Immutable/src/System/Collections/Frozen/Constants.cs
Outdated
Show resolved
Hide resolved
* use nint and nuint rather than IntPtr and UIntPtr * add tests for Frozen Dictionaries with key being uint, short, ushort, byte, sbyte
src/libraries/Common/tests/System/Collections/ICollection.Generic.Tests.cs
Outdated
Show resolved
Hide resolved
src/libraries/Common/tests/System/Collections/IDictionary.Generic.Tests.cs
Show resolved
Hide resolved
src/libraries/System.Collections.Immutable/tests/Frozen/FrozenDictionaryTests.cs
Show resolved
Hide resolved
src/libraries/System.Collections.Immutable/tests/Frozen/FrozenDictionaryTests.cs
Show resolved
Hide resolved
@jkoritzinsky I've synced my branch with upstream and everything works fine. Thanks for letting me know! |
src/libraries/Common/tests/System/Collections/ICollection.Generic.Tests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Collections.Immutable/tests/Frozen/FrozenDictionaryTests.cs
Show resolved
Hide resolved
and also fix a discovered bug: IntPtr started implementing IComparable<IntPtr> in .NET 5
byte[] bytes = new byte[8]; | ||
random.NextBytes(bytes); | ||
return BitConverter.ToInt64(bytes, 0); | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not going to matter for testing purposes, but technically these aren't the same thing. NextInt64(long.MinValue, long.MaxValue) will never produce long.MaxValue, but the else code can. For simplicity you might want to just delete the NET6_0_OR_GREATER case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will never produce long.MaxValue, but the else code can.
Good point! After thinking about it I decided to remove the NET6_0_OR_GREATER case as it could cause another kind of issues: generate different output for the same input and hence get us to a situation where exactly the same test is passing for one moniker and failing for another.
The failure is unrelated (#87477), merging. |
@stephentoub this is my last PR for frozen collections perf for now
I apologize if the CI gets red, for some reason I am getting a build error and I temporarily can't run unit tests locally:
contributes to #87964 and closes #87964 it as it's the last PR in the series